<template>
  <el-cascader :value="value" :options="list" size="mini" :props="{label:'name',value:'id'}" separator="-" @change="onSelect" />
</template>

<script>
import { getDepartmentAPI } from '@/api/department'
import { transListToTreeData } from '@/utils'

export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      list: []
    }
  },
  async created() {
    const res = await getDepartmentAPI()
    const xxx = transListToTreeData(res, 0)
    this.list = xxx
  },
  methods: {
    onSelect(val) {
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style lang="scss" scoped></style>
